package com.qf.petmall.starter.utils;

import com.github.wxpay.sdk.WXPay;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 可乐
 * @Description:
 * @CreateTime: 2022-11-11  09:14
 */
public class WxpayUtils {
	public  static HashMap<String, String> params = new HashMap<>();

	public static String getPayUrl(String orderId,String describe) throws Exception {

		//设置当前订单信息
		HashMap<String,String> data = new HashMap<>();
		data.put("body",describe);  //商品描述
		data.put("out_trade_no",orderId);               //使用当前用户订单的编号作为当前支付交易的交易号
		data.put("fee_type","CNY");                     //支付币种
		//data.put("total_fee",order.getActualAmount()*100+"");          //支付金额
		data.put("total_fee","1");
		data.put("trade_type","NATIVE");                //交易类型
		data.put("notify_url","http://192.168.10.81:8878/order/callback");           //设置支付完成时的回调方法接口

		//发送请求，获取响应
		//微信支付：申请支付连接
		WXPay wxPay = new WXPay(new MyPayConfig());
		Map<String, String> resp = wxPay.unifiedOrder(data);
		return resp.get("code_url");

	}


	public static String queryOrder(String orderId) throws Exception {

		params.put("out_trade_no", orderId);
		WXPay wxPay = new WXPay(new MyPayConfig());
		Map<String, String> resp = wxPay.orderQuery(params);
		return resp.get("trade_state");
	}

	//取消订单；
	public static Boolean cancelOrder(String orderId) throws Exception {

		WXPay wxPay = new WXPay(new MyPayConfig());
		Map< String, String > map=wxPay.closeOrder( params );
		return true;
	}



}
